define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
	    /**
	     * 一键绑定数据获取方式
	     * @param {Object} retsult
	     */
	    function get_data_getlist(result){
	        if(false){
	            result='{"success":true,"msg":"","result":{"page":[{"limit":8,"tPage":1,"cPage":5,"count":3}],"beagenter":[{"info_id":1,"region_name":"广西","cat_type_name":"扳手类","apply_time":"2017-04-12 9:00:00","status":"审核不通过"},{"info_id":1,"region_name":"广西","cat_type_name":"扳手类","apply_time":"2017-04-12 9:00:00","status":"审核通过"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
	            return JSON.parse(result);
	        }else{
	            return result;
	        }
	    };
        //发布代理
        function get_data_edit(result) {
            if(false) {
                result = '{"success": true,"msg": "","result": {"info_id":"001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        };
        //根据id查找
		function get_data_findById(result) {
            if(false) {
                result = '{"success": true,"msg": "","result": {"info_id":"001","cat_type_id":"4398","region_id":"158","requirement":"这是我的需求描述喔，我需要一批工具。","money":"20000","phone":"13617739888"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
      		}
        };
        //删除
        function get_data_delete(result) {
            if(false) {
                result = '{"success": true,"msg": "","result": "","session": "7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        };


		//返回信息
		return {
		    //获取代理发布信息
		    getlist:function(pagelimit,nPage,callback,calldone){
		        Http.post({
		            method: 'member.beagenter.getlist',
                    pagelimit: pagelimit,
                    nPage: nPage
		        },
		        function(result) {
                    //请求成功
                    if(callback)
                        callback(get_data_getlist(result).result);
                },
                function(e) {
                        //请求异常
                },
                  function() {
                    //请求完成，一般不做什么事情
                    if(calldone)
                		calldone();
                });
		    },

			//发布代理或修改
                beagenter_edit: function(info_id,cat_type_id,region_id,reason,capital,phone, callback) {
                    var params=new Object();
                    params.info_id=info_id;
                    params.cat_type_id=cat_type_id;
                    params.region_id=region_id;
                    params.reason=reason;
                    params.capital=capital;
                    params.phone=phone;
                    params=JSON.stringify(params);
                Http.post({
                        method: 'member.beagenter.edit',
                        updateParams:params
                    },
                    function(result) {
                        //请求成功
                        if(callback)
                            callback(get_data_edit(result));
                    },
                    function(e) {
                        //请求异常
                    },
                    function() {
                        //请求完成，一般不做什么事情
                    });
            },
			findById: function(info_id, callback) {
				Http.post({
						method: 'member.beagenter.detail',
						info_id: info_id
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_findById(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					});
			},
			delete_info_id:function(info_id,callback){
                Http.post({
                        method: 'member.beagenter.delete',
                        info_id: info_id
                    },
                    function(result) {
                        //请求成功
                        if(callback)
                            callback(get_data_delete(result));
                    },
                    function(e) {
                        //请求异常
                    },
                    function() {
                        //请求完成，一般不做什么事情
                    });
           }


		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Wanttoagent", factory);
});